﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.JinShengService;

namespace CommunitySystem.PageView.晋升管理.新的晋升管理
{
    public partial class XJJGWindow : ChildWindow
    {
        private JinShengServiceClient _client = new JinShengServiceClient();
        private JinShen_XuanJu entity = new JinShen_XuanJu();
        private JinShen_PublicShow_Detail psdetail = null;
        public XJJGWindow(JinShen_MainInfo _mainInfo, JinShen_PublicShow_Detail Detail,string Role)
        {
            InitializeComponent();

            _client.GetOrgForHRCompleted += (sender, e) =>
            {
                Role = e.Result;
                //管理员只能查看  或者 晋升确认  晋升成功了 
                if (JinShenConst.Administrator.Contains(Role) || _mainInfo.Status == JinShenConst.STATUS_Promot_Apply || _mainInfo.Status == JinShenConst.STATUS_Promot_Agree)
                    this.OKButton.IsEnabled = false;
            };
            _client.GetOrgForHRAsync(EHR.Common.Session.LoginUser.LoginName);
           


            psdetail = Detail;
            entity.MainID = psdetail.MainID;
         //   dpdata.Text = DateTime.Now.ToShortDateString();
            _client.SaveJinShen_XuanJuCompleted += (sender, e) => {

                 entity = e.Result;
                 if (entity != null)
                 {
                     dpdata.Text = e.Result.StartDate.ToString();
                 }
                 if (entity == null)
                 {
                     SilverlightMessageBoxLibrary.Message.InfoMessage("选举成功!");
                     this.DialogResult = true;
                 }
                
            };
            _client.SaveJinShen_XuanJuAsync(entity,true);

            var dgwxx = _mainInfo.DangGongWei_Detail.Where(p => p.MainID == Detail.MainID).Where(p=>p.EmpID==Detail.EmpID).First();
        
           // this.tbPosi.Text = _mainInfo.Position + "(" + _mainInfo.PositionLevel + ")";
            this.tbName.Text = dgwxx.EmpName;
            this.tbPosi.Text = dgwxx.Position + "(" + dgwxx.AttributLevel + ")";


        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.dpdata.SelectedDate == null)
            {
                MessageBox.Show("日期不能为空,请选择日期！");
                    return;
            }
            if (entity == null) entity = new JinShen_XuanJu();
            entity.EmpID = psdetail.EmpID;
            entity.EmpName = psdetail.EmpName;
            entity.StartDate = this.dpdata.SelectedDate;
            entity.MainID = psdetail.MainID;
            _client.SaveJinShen_XuanJuAsync(entity,false);
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

